package pokerantani.v2;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import pokerantani.v2.model.Card;


public abstract class LineMatcher {
	private Matcher matcher;
	
	public abstract boolean match(String line);
	
	protected boolean match(String s, Pattern p) {
		matcher = p.matcher(s);
		if(matcher.matches()) return true;
		matcher = null;
		return false;
	}
	
	protected String group(int i) {
		return matcher.group(i);
	}
	
	protected int groupInt(int i) {
		return Integer.parseInt(matcher.group(i));
	}
	
	protected float groupFloat(int i) {
		return Float.parseFloat(matcher.group(i));
	}
	
	protected Card groupCard(int i) {
		return new Card(group(i));
	}
	
	protected List<Card> groupCards(int... positions) {
		List<Card> cards = new ArrayList<Card>();
		for(int i = 0; i < positions.length; i++)
			cards.add(groupCard(positions[i]));
		return cards;
	}
}
